//
//  ScrollViewMasonry.m
//  ScrollViewInMasonryBeta
//
//  Created by king on 15/11/30.
//  Copyright © 2015年 king. All rights reserved.
//

#import "ScrollViewMasonry.h"
#import "Masonry.h"

@implementation ScrollViewMasonry

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createScrollView];
        [self createContentView];
        [self loadImage];
    }
    return self;
}

- (void)createScrollView {
    self.scrollView = [[UIScrollView alloc] init];
    self.scrollView.backgroundColor = [UIColor yellowColor];
    [self addSubview:self.scrollView];
    self.scrollView.bounces = NO;
    self.scrollView.pagingEnabled = YES;
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(self.mas_width);
        make.height.mas_equalTo(self.mas_height);
    }];
}

- (void)createContentView {
    self.contenView = [[UIView alloc] init];
    [self.scrollView addSubview:self.contenView];
    self.contenView.backgroundColor = [UIColor redColor];
    [self.contenView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.scrollView);
        make.height.equalTo(self.scrollView);
    }];
}

- (void)loadImage {
    UIImageView *lastView = nil;
    for (int i = 1; i < 4; i++) {
        UIImageView *subv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"ad%d.png", i]]];
        [self.contenView addSubview:subv];
        
        [subv mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(lastView ? lastView.mas_right : @0);
            make.bottom.equalTo(@0);
            make.width.equalTo(self.scrollView.mas_width);
            make.height.equalTo(self.scrollView.mas_height);
        }];
        lastView = subv;
    }
    [self.contenView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(lastView.mas_right);
    }];

}




































@end
